<template>
  <div class="picture-view">
    <img :src="autoCover" />
    <div class="mask" @click="openDraw()">
      <div class="inner_text_box">
        <i class="el-icon-camera"></i>查看全部图片
      </div>
    </div>
    <div class="drawer" @click.self="closeDraw()" v-show="on">
      <div class="card">
        <div class="card-left">
          <img :src="list[currentIndex]" alt="" />
        </div>
        <div class="card-right">
          <div
            class="list-node"
            v-for="(item, i) in list"
            :key="i"
            @click="changePic(i)"
          >
            <img
              v-if="i == currentIndex"
              :src="item"
              alt=""
              class="active-img"
            />
            <img v-else :src="item" alt="" />
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    list: Array,
    cover: String,
  },
  data() {
    return {
      on: false,
      currentIndex: 0,
    };
  },
  computed: {
    autoCover() {
      if (this.cover) {
        console.log(this.cover);
        return this.cover;
      } else if (this.list.length > 0) {
        return this.list[0];
      } else {
        return "";
      }
    },
  },
  methods: {
    openDraw() {
      this.on = true;
    },
    closeDraw() {
      this.on = false;
    },
    changePic(i) {
      this.currentIndex = i;
    },
  },
};
</script>

<style lang="less" scoped>
.picture-view {
  position: relative;
  height: 100%;
  width: 100%;
  img {
    height: 100%;
    width: 100%;
    object-fit: cover;
  }
  .mask {
    &:hover {
      cursor: pointer;

      opacity: 1;
    }
    opacity: 0;
    top: 0;
    left: 0;
    position: absolute;
    width: 100%;
    height: 100%;
    background-color: rgba(99, 99, 99, 0.4);
    transition: all 0.5s;
    display: flex;
    justify-content: center;
    align-items: center;
    .inner_text_box {
      color: #fff;
      font-size: 1rem;
    }
  }
  .drawer {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(99, 99, 99, 0.3);
    z-index: 500;
    display: flex;
    justify-content: center;
    align-items: center;
    .card {
      max-width: 80%;
      height: 80%;
      overflow: hidden;
      display: flex;
      flex-direction: row;
      justify-content: flex-end;
      .card-left {
        background-color: rgba(99, 99, 99, 0.7);
        position: relative;
        
        height: 100%;
        img {
          width: 100%;
          height: 100%;
          object-fit: scale-down;
        }
      }
      .card-right {
        width: 300px;
        background-color: #fff;
        display: flex;
        flex-direction: row;
        justify-content: flex-start;
        align-items: flex-start;
        align-content: flex-start;
        flex-wrap: wrap;
        overflow: scroll;
        &::-webkit-scrollbar {
          display: none;
        }
        .list-node {
          padding: 10px;
          width: 100px;
          height: 100px;
          img {
            border: 3px solid rgba(0, 0, 0, 0);
            object-fit: cover;
            &:hover {
              border: 3px solid #000;
              cursor: pointer;
            }
          }
          .active-img {
            border: 3px solid #000;
          }
        }
      }
    }
  }
}
</style>

